package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.CheckitemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckitemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CheckitemServiceImpl extends ServiceImpl<CheckitemMapper, CheckItem> implements CheckitemService {


    public Map findPage(QueryPageBean queryPageBean){
        QueryWrapper<CheckItem> checkItemQueryWrapper = new QueryWrapper<>();
        String queryString = queryPageBean.getQueryString();
        checkItemQueryWrapper.like("name",queryString==null?"":queryString);
        checkItemQueryWrapper.eq("is_delete",0);
        Page<CheckItem> page = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), checkItemQueryWrapper);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",page.getTotal());
        map.put("list",page.getRecords());
        return map;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
        List<CheckItem> list = list(queryWrapper);
        return list;
    }

}


